import { wxLiveUserInfo } from '@/api/small/login'
import small from './small'

export default {
  // 拍对直播对接方法
  wxPdZb(zbQuery) {
    if (small.globalData.isPdZb == 1) {
      wxLiveUserInfo().then(pd => {
        if (pd.status == 1) {
          const pdData = pd.data
          let plugin = requirePlugin("pd-plugin"),
                userInfo = {
                    openid: pdData.openid,
                    unionid: pdData.unionid,
                    phone: pdData.mobile,
                    nickname: pdData.nickname,
                    headimgurl: pdData.headimgurl,
                },
                shareData = {
                  pid: pdData.user_id,
                  sid: pdData.shop_id,
                  path: `/pages/pdzbShare/index?type=open&targeturl=${encodeURIComponent('/pdzb-share')}&pid=${pdData.user_id}&sid=${pdData.shop_id}`,
                  isZb: 1
                };  
          plugin.setUserInfo(userInfo);
          plugin.setShareData(shareData);

          let data = {  
            homePageUrl:`/pages/shopIndex/index?type=open&targeturl=${encodeURIComponent('/index')}`
          }
          plugin.setConfig(data)
          
          if (zbQuery.isRoom == 1) {
            wx.redirectTo({
              url: `plugin-private://wx5d130e4479328f39/pages/living-detail/index?roomId=${zbQuery.roomId}&recordId=${zbQuery.recordId}`
            })
          } else {
            wx.redirectTo({
              url: `plugin-private://wx5d130e4479328f39/pages/living-list/index`,
            })
          }
        }
      })
    }
  }
}